<template>

	<custom-page-select-layout>
		<template #header>
			<fui-search-bar paddingTb="0" searchText="" paddingLr="0" radius="16" height="80" inputBackground="#F3F3F3"
				isLeft :cancel="false" @clear="onClear" @input="onChangeKeywords"></fui-search-bar>
		</template>
		<template #body>

			<fui-checkbox-group @change="changeCheckBox" :modelValue="checkValue">
				<custom-index-list isSelect custom :listData="rewriteList">
					<template v-slot:item="{ model, idx, index }">
						<fui-label bottomBorder topBorder>
							<fui-list-cell>
								<view class="fui-align__center">
									<fui-checkbox :value="model.objectValue"></fui-checkbox>
									<text style="margin-left: 16rpx;">{{model.text}}</text>
								</view>
							</fui-list-cell>
						</fui-label>
					</template>

				</custom-index-list>
			</fui-checkbox-group>
		</template>
		<template #footer>
			<fui-row class="button-wrapper" :gutter="16">
				<fui-col :span="6">
					<fui-button background="#F2F3FF" color="#0052D9" @click="onCancel">
						取消
					</fui-button>
				</fui-col>
				<fui-col :span="18">
					<fui-button @click="onConfirm">
						确认
					</fui-button>
				</fui-col>
			</fui-row>
		</template>
	</custom-page-select-layout>

</template>

<script>
	import {
		useSelectUserPageStore
	} from '../../store/modules/selectUserPage.js';
	import {
		mapState,
		mapActions
	} from 'pinia'

	import {
		defineComponent
	} from "vue";
	import {
		useSyStemStore
	} from '../../store/modules/system.js';
	export default defineComponent({
		data() {
			return {
				show: false,
				storeKey: '',
				backToPath: null,
			}
		},
		computed: {
			...mapState(useSelectUserPageStore, ['userStoreKey', 'rewriteList', 'indexList', 'checkedValue']),
			...mapState(useSyStemStore, ['userList']),
			checkValue() {
				return this.userStoreKey[this.storeKey].value
			}
		},
		onLoad(options) {
			const is = {
				'false': false,
				'true': true
			}
			this.storeKey = options.storeKey
			this.multiple = is[options.multiple]
			this.backToPath = options.backToPath
			this.setInit(this.userList)
		},
		methods: {
			...mapActions(useSelectUserPageStore, ['setInit', 'onChangeKeywords', 'setUserStoreKeyValue']),

			onClear() {
				this.onChangeKeywords({
					detail: {
						value: ''
					}
				})
			},
			init() {
				this.show = true;
			},

			changeCheckBox(e) {
				this.setUserStoreKeyValue(e.detail.value, this.storeKey)

			},
			onConfirm() {
				if (this.backToPath) {
					uni.redirectTo({
						url: this.backToPath
					})
				}

			},
			onCancel() {
				// if (this.data.backToPath) {
				//   wx.redirectTo({
				//     url: `${this.data.backToPath}`,
				//   })
				// } else {
				//   wx.navigateBack()
				// }
			},
		}
	})
</script>

<style>
	page {
		font-weight: normal;
	}
</style>